/*
 *
 *
 * Copyright  1990-2009 Sun Microsystems, Inc. All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License version
 * 2 only, as published by the Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License version 2 for more details (a copy is
 * included at /legal/license.txt).
 * 
 * You should have received a copy of the GNU General Public License
 * version 2 along with this work; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 * 
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
 * Clara, CA 95054 or visit www.sun.com if you need additional
 * information or have any questions.
 */
#ifndef _MIDP_FILE_CACHE_H_
#define _MIDP_FILE_CACHE_H_

#include <midpString.h>
#include <midpStorage.h>
#include <midp_constants_data.h>
#include <java_types.h>

typedef struct _MidpFileCacheBlock {
    struct _MidpFileCacheBlock *next;	/* next cache block */
    long position;			/* file offset */
    long length;			/* size of the data block */
    /* char data[0];			   data buffer */
} MidpFileCacheBlock;

typedef struct _MidpFileCache {
    int handle;
    int size;
    StorageIdType storageId;
    long cachedPosition;
    long cachedFileSize;
    jlong cachedAvailableSpace;
    MidpFileCacheBlock *blocks;
} MidpFileCache;

void midp_file_cache_flush(char** ppszError, int handle);

int midp_file_cache_open(char** ppszError, StorageIdType storageId,
                         const pcsl_string* filename, int ioMode);

void midp_file_cache_close(char** ppszError, int handle);

void midp_file_cache_seek(char** ppszError, int handle, long position);

void midp_file_cache_write(char** ppszError, int handle,
                           char* buffer, long length);

long midp_file_cache_read(char** ppszError, int handle,
                          char* buffer, long length);

jlong midp_file_cache_available_space(char** ppszError, int handle,
                                      StorageIdType storageId);

long midp_file_cache_sizeof(char** ppszError, int handle);

void midp_file_cache_truncate(char** ppszError, int handle, long size);

#endif
